package com.example.demo.mapper;

import com.example.demo.model.entity.Goods;
import com.example.demo.util.PageInfo;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface GoodsMapper {
    @Select("select * from goods where id = #{id}")
    Goods selectById(int id);

    @Insert("insert into goods (name, price, description, img_url) values(#{name}, #{price}, #{description}, #{imgUrl})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    void insert(Goods goods);

    @Update("update goods set name = #{name}, price = #{price}, description = #{description}, img_url = #{imgUrl} where id = #{id}")
    void update(Goods goods);

    @Delete("delete from goods where id = #{id}")
    void delete(int id);

    @Select("select * from goods limit #{offset}, #{limit}")
    List<Goods> pageQuery(int limit, int offset);

    @Select("select count(*) from goods")
    long getCount();
}
